import 'package:flutter/material.dart';
import '../../../utils/base.dart';

class UserItem extends StatelessWidget {
  final String avatar;

  final String nickname;

  final String memberId;

  final int point;

  const UserItem(
      {Key key, this.avatar, this.nickname, this.memberId, this.point})
      : super(key: key);

  Widget _avatar() {
    return Container(
      child: Hero(
        tag: avatar,
        child: ClipOval(
          child: FadeInImage.assetNetwork(
            placeholder: "assets/logo.png", //预览图
            fit: BoxFit.cover,
            image: avatar,
            width: Design.px(100),
            height: Design.px(100),
          ),
        ),
      ),
    );
  }

  Widget _userInfo() {
    return Container(
      alignment: Alignment.centerLeft,
      padding: EdgeInsets.symmetric(horizontal: Design.px(20)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(
            '$nickname（$memberId）',
            style:
                TextStyle(fontSize: Design.px(44), color: HexColor('333333')),
          ),
          Text(
            '积分：$point',
            style:
                TextStyle(fontSize: Design.px(28), color: HexColor('666666')),
          ),
        ],
      ),
    );
  }

  Widget _actions() {
    double size = Design.px(80);

    BorderRadius _roundRadius = BorderRadius.circular(size);

    return Container(
      decoration: BoxDecoration(
        borderRadius: _roundRadius,
        gradient: LinearGradient(
          begin: Alignment.centerLeft,
          end: Alignment.centerRight,
          colors: [HexColor('ff91a2'), HexColor('ff6a75')],
        ),
      ),
      child: ClipOval(
        child: Container(
          width: size,
          height: size,
          alignment: Alignment.center,
          child: Text('查看\n详情',
              style: TextStyle(
                  fontSize: Design.px(20), color: HexColor('FFFFFF'))),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
        decoration: BoxDecoration(
          color: HexColor("ffffff"),
          borderRadius: new BorderRadius.circular(Design.px(17)),
          boxShadow: [
            new BoxShadow(
                color: HexColor("f1f1f1"),
                offset: new Offset(Design.px(10), Design.px(10)),
                blurRadius: Design.px(10),
                spreadRadius: Design.px(2))
            // BoxShadow(color: Color(0x99FFFF00), offset: Offset(5.0, 5.0),    blurRadius: 10.0, spreadRadius: 2.0),
            // BoxShadow(color: Color(0x9900FF00), offset: Offset(1.0, 1.0)),
            // BoxShadow(color: Color(0xFF0000FF))
          ],
        ),
        child: FlatButton(
          onPressed: () =>
              {Navigator.of(context).pushNamed('/user_manager/detail')},
          shape: new RoundedRectangleBorder(
              borderRadius: new BorderRadius.circular(Design.px(17))),
          child: Row(
            children: <Widget>[
              _avatar(),
              Expanded(
                child: _userInfo(),
              ),
              _actions(),
            ],
          ),
        ));
  }
}
